<template>
  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header style="text-align: right; font-size: 12px">
      <div class="item_name">后台管理系统</div>
      <el-button type="info" @click="quit">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏区域 -->
      <el-aside :width="istoggle ? '64px' : '200px' ">
        <div class="toggle_button" @click="toogleAside">|||</div>
        <el-menu
          :default-active="acitvePath"
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#3a8ee6"
          :unique-opened="true"
          :collapse="istoggle"
          :collapse-transition="false"
          :router="true"
        >
          <el-submenu :index="item.id+''" v-for="item in asideList" :key="item.id">
            <template slot="title">
              <i :class="asideIcon[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item v-for="item1 in item.children" :key="item1.id" :index="'/'+item1.path" @click="setcurrentindex('/'+item1.path)">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{item1.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主题区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      acitvePath:'',
      istoggle: false,
      asideList: [],
      asideIcon: {
        "125": "el-icon-user-solid",
        "103": "el-icon-s-tools",
        "101": "el-icon-s-goods",
        "102": "el-icon-s-order",
        "145": "el-icon-s-operation"
      }
    };
  },
  methods: {
    quit() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getAsideList() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status !== 200) return this.$message.error("获取侧边栏失败");
      this.asideList = res.data;
    },
    toogleAside() {
      this.istoggle = !this.istoggle;
    },
    setcurrentindex(index){
         window.sessionStorage.setItem("acitvePath",index)
         this.acitvePath=index;
    }
  },
  created() {
    this.getAsideList();
    this.acitvePath= window.sessionStorage.getItem('acitvePath')
  }
};
</script>
<style lang="less" scoped>
.home_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .item_name {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
    line-height: 60px;
  }
}

.el-aside {
  background-color: #333744;
  color: #fff;
  text-align: center;
  .toggle_button {
    line-height: 30px;
    background-color: #4a5064;
    cursor: pointer;
  }
}
.el-menu {
  border: 0;
}
.el-main {
  background-color: #e9eef3;
  min-height: 100%;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}
.el-submenu {
  color: #fff;
}
.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>